package utools

import (
	"encoding/json"
	"errors"
	"github.com/gofiber/fiber/v2"
)

type MessageStruct struct{}

type Structure struct {
	Status  bool   `json:"status"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

var Message MessageStruct

func (MessageStruct) Success(data any, ctx *fiber.Ctx) (string, error) {
	relData, err := json.Marshal(Structure{Status: true, Message: "success", Data: data})
	if err == nil {
		ctx.Send(relData)
	}
	return string(relData), err
}

func (MessageStruct) Error(errorMessage string, ctx *fiber.Ctx) (error, error) {
	relData, err := json.Marshal(Structure{Status: false, Message: errorMessage, Data: nil})
	if err == nil {
		ctx.Send(relData)
	}
	return errors.New(string(relData)), err
}
